package com.msds.parent.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.junit.Test;

import com.msds.parent.common.util.ConstatFinalUtil;

public class testHw extends ConstatFinalUtil
{
    @Test
    public void testShiro(){
    	try
		{
			/*构建securityManager的工厂*/
    		Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:shiro.ini");
		    /*获取securityManager的一个对象*/
    		SecurityManager securityManager=factory.getInstance();
    		/*将安全管理器设置到运行环境中*/
    		SecurityUtils.setSecurityManager(securityManager);
    		/*获取subject对象*/
    		Subject subject=SecurityUtils.getSubject();
    		/*创建一个用户名和密码*/
    		UsernamePasswordToken usernamePasswordToken=new UsernamePasswordToken("zhangsan","111111");
    		/*登陆*/
    		subject.login(usernamePasswordToken);
    		
    		LOGGER.info("执行结果：{}",subject.isAuthenticated());
    				
		} catch (Exception e)
		{
			e.printStackTrace();
		}
    }
}
